<template>
	<div class="add-jq-dialog">
		<!--设置主机所在集群-->
		
		
		<appdialog 
			ref="dialog"
			:visible="false" 
			title="设置集群"
			@confirm="confirmAdd"
			@cancle="cancleAdd"
			width="30%"
			>
			
			<el-form 
				ref="addForm" 
				:rules="rules" 
				:model="addForm"
				label-width="100px"
				>
			  
			  <el-form-item label="名称：" prop="clusterId">
					<jiqunSelect
						defaultValue=""
						@change="clusterIdChange"
						></jiqunSelect>
				</el-form-item>
				
			</el-form>
			
		</appdialog>
		
	</div>
</template>

<script>

import appdialog from "@/view/components/dialog/dialog";

import jiqunSelect from "@/view/components/select/jiqunSelect";

import {updateHostCluster} from "@/service/swagger/ResourceHostController"

export default {
	name: "setZJJQDialog",
	components: {
		appdialog,
		jiqunSelect,
	},
	data() {
    return {
      addForm : {
      	clusterId : "", // 设置主机 所到的集群 id
      	params : {}
      },
      rules : {
      	'clusterId': [
          { required: true, message: ' ', trigger: 'blur' },
        ],
      }
    }
  },
  mounted() {
  	
  },
	methods:{
   	open(ipInfo){
   		this.$refs.dialog.open();
   		this.addForm.params = ipInfo ;
   	},
   	
   	confirmAdd(){
   		console.log("确认添加" , this.addForm )
   		
   		// 验证表单
   		this.$refs.addForm.validate((valid) => {
        if (valid) {
        	// 验证通过
          this.submitAdd();
        } else {
        	setTimeout(()=>{
        		this.open();
        	},50)
          
          return false;
        }
      });
   		// 
   	},
   	submitAdd(){
   		
   		let params = {
   			ip : this.addForm.params.ip ,
   			clusterId : this.addForm.clusterId,
   		}
   		
   		updateHostCluster(params).then(ret=>{
   			this.$message({
          message: '修改成功',
          type: 'success',
          duration : 2000,
        });
        
        this.$refs.dialog.close();
        this.$emit("addSucess")
   		})

   	},
   	cancleAdd(){
   		
   	},
   	
   	clusterIdChange(name,v){
   		this.addForm.clusterId = v;
   	},
   	
	}
}
</script>

<style scoped lang="scss">
@import "../../../styles/variables.scss";


</style>